<?php
class View_Admin_UserManangement extends View_Admin_Index_Template {
    public $oTemp;
    public function displayManagerIndex($oModel) {
        $this->initTemplate($oModel);
        $this->oTemp->assign_file( 'tempMainContent', PATH_TEMPLATE_ADMIN.'html/user_manager_index.html' );
        $this->oTemp->assign('pageHeding',$oModel->aLanguage[MODULE_HEADING]['manager']);
        /**
         * toolbar setup
         */
        $this->oTemp->assign('toobar_new','?sMod=user_index&sAction=add_new_form');
        $this->oTemp->parse('main.toobar_new');
        $this->oTemp->assign('toobar_save',"formSubmit('frmUpdate')");
        $this->oTemp->parse('main.toobar_save');
    }

    public function displayListUser($oModel) {
        $rs=$oModel->getListUser();
        if(is_array($rs)) {
            $i=0;
            foreach($rs as $row) {
                $i++;
                $row['css'] = "row".($i%2);
                $row['no'] = $i;
                if($row['admin_status']==1) {
                    $row['admin_status']='checked';
                }
                if($row['admin_role']==1) {
                    $row['admin_role']=$oModel->aLanguage[MANAGER]['supper_admin'];
                }
                else if($row['admin_role']==2){
                	$row['admin_role']=$oModel->aLanguage[MANAGER]['admin'];
                }
                else{
                	$row['admin_role']=$oModel->aLanguage[MANAGER]['shop_owner'];
                        $row['admin_role'] = '<a href="?sMod=user_index&sAction=setting_default&id='.$row['admin_id'].'" title="'.$oModel->aLanguage['MANAGER']['lb_edit_setting_default'].'">'.$row['admin_role'].'</a>';
                }
                    
                $this->oTemp->assign('rowManager',$row);
                $this->oTemp->parse('main.rowManager');

            }
        }
        $this->oTemp->assign( 'navigator', $oModel->oNavigator->navigator() );
    }

    /**
     * ADD NEW USER
     */
    public function displayNewUserIndex($oModel) {
        $this->initTemplate($oModel);
        $this->oTemp->assign_file( 'tempMainContent', PATH_TEMPLATE_ADMIN.'html/user_manager_new.html' );
        $this->oTemp->assign('pageHeding',$oModel->aLanguage[MODULE_HEADING]['manager']);
        /**
         * toolbar setup
         */
        $this->oTemp->assign('toobar_save','check_user_form()');
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_cancel','?sMod=user_index');
        $this->oTemp->parse('main.toobar_cancel');

        $template_id = $oUser['admin_template_id'];
        $category_id = $oUser['admin_category_id'];

        $oTemplates = $oModel->getTemplate();
        foreach($oTemplates as $temp){
            if($temp['id']==$template_id){
                $temp['select'] = 'selected="selected"';
            }
            else{
                $temp['select'] = '';
            }
            $this->oTemp->assign("template_default",$temp);
            $this->oTemp->parse("main.template");
        }

        $oCategory = $oModel->getRootCategory();
        foreach($oCategory as $oCat){
            if($oCat['product_category_id'] == $category_id){
                $oCat['select'] = 'selected="selected"';
            }
            else{
                $oCat['select'] = '';
            }
            $this->oTemp->assign("category",$oCat);
            $this->oTemp->parse("main.root_category");
        }
    }
    /**
     * EDIT USER
     */
    public function displayEditUserIndex($oModel) {
        $this->initTemplate($oModel);
        $this->oTemp->assign_file( 'tempMainContent', PATH_TEMPLATE_ADMIN.'html/user_manager_edit.html' );

        $this->oTemp->assign('pageHeding',$oModel->aLanguage[MODULE_HEADING]['manager']);
        /**
         * toolbar setup
         */
        $this->oTemp->assign('toobar_save','check_edit_form()');
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_cancel','?sMod=user_index');
        $this->oTemp->parse('main.toobar_cancel');
    }

    public function displayInfoUser($oModel) {
        $rowManager = $oModel->getInfoUser();
        if($rowManager['admin_status']==1)
            $rowManager['admin_status']="checked";
        if($rowManager['admin_role']==1) {
            $rowManager['admin_role_1']='selected="selected"';
        }
        elseif($rowManager['admin_role']==2) {
            $rowManager['admin_role_2']='selected="selected"';
        }
        $this->assignExtract($rowManager);
    }
    public function displaySettingInfo($oModel,$oUser){
        
        $this->initTemplate($oModel);
        $this->oTemp->assign_file( 'tempMainContent', PATH_TEMPLATE_ADMIN.'html/user_manager_default.html' );

        $this->oTemp->assign('pageHeding',$oModel->aLanguage[MODULE_HEADING]['manager']);
        /**
         * toolbar setup
         */
        $this->oTemp->assign('toobar_save','submit_setting_default()');
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_cancel','?sMod=user_index');
        $this->oTemp->parse('main.toobar_cancel');

        $template_id = $oUser['admin_template_id'];
        $category_id = $oUser['admin_category_id'];

        $oTemplates = $oModel->getTemplate();
        foreach($oTemplates as $temp){
            if($temp['id']==$template_id){
                $temp['select'] = 'selected="selected"';
            }
            else{
                $temp['select'] = '';
            }
            $this->oTemp->assign("template_default",$temp);
            $this->oTemp->parse("main.template");
        }

        $oCategory = $oModel->getRootCategory();
        foreach($oCategory as $oCat){
            if($oCat['product_category_id'] == $category_id){
                $oCat['select'] = 'selected="selected"';
            }
            else{
                $oCat['select'] = '';
            }
            $this->oTemp->assign("category",$oCat);
            $this->oTemp->parse("main.root_category");
        }
    }
}
